﻿package domino 
{
	import flash.geom.Point;
	import flash.display.DisplayObjectContainer;
	import flash.geom.Point;
	import flash.display.Sprite;
	
	import Box2D.Dynamics.*;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	/**
	 * ...
	 * @author adgard ...
	 */
	public class actorWall extends actor
	{
		
		public function actorWall(_world:b2World,parent:DisplayObjectContainer,dominPosition:Point,_DomArray:Array,isSensor:int)
		{
			//create costume
			var dominSprite:Sprite = new Sprite();
			
			for each(var wallPoint:Array in _DomArray)
			  {
				  var firstPoint:Point = wallPoint[0];
				  dominSprite.graphics.lineStyle(2,0x3278CD);
				  dominSprite.graphics.moveTo(firstPoint.x,firstPoint.y);
			      
				  for each(var nextPoint:Point in wallPoint){
			         dominSprite.graphics.beginFill(0x3278CD,1);
					 dominSprite.graphics.lineTo(nextPoint.x,nextPoint.y); 
					 dominSprite.graphics.moveTo(nextPoint.x,nextPoint.y);
				  }
				  dominSprite.graphics.lineTo(firstPoint.x,firstPoint.y); 
				  dominSprite.graphics.endFill();
				  
				  dominSprite.x = dominPosition.x;
				  dominSprite.y = dominPosition.y;
				  
				  parent.addChild(dominSprite);
			  }
			 
			 
			 
			 
			//create body
			var final_body:b2Body;
			var the_body:b2BodyDef;
			var the_box:b2PolygonDef;
			
			the_body = new b2BodyDef();
			the_body.position.Set(dominPosition.x/30,dominPosition.y/30);

			
			
			
			final_body = _world.CreateBody(the_body);
			
			for each(var wallPoint2:Array in _DomArray) {
				 
				 the_box = new b2PolygonDef();
			     the_box.vertexCount = wallPoint2.length;
				 
				 for (var i:int = 0; i < wallPoint2.length; i++ ) {
					   the_box.vertices[i].Set(wallPoint2[i].x/30,wallPoint2[i].y/30);
				   }
				 the_box.friction=0.3;	
			     the_box.density = 0.0;
				 the_box.isSensor = isSensor;
				 final_body.CreateShape(the_box);
				}
			final_body.AllowSleeping(true);
			final_body.SetMassFromShapes();
	
			
			super(final_body,dominSprite);
		}
	
		
	}
}